package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCChildrenReplacementRMAInfo;
import com.shrct.businessprocess.customerservice.RCFaultReport;
import com.shrct.businessprocess.customerservice.RCFaultReportProduct;
import com.shrct.businessprocess.customerservice.impl.RCFaultReportRMAInfoImpl;
import com.shrct.businessprocess.customerservice.proxy.RCChildrenReplacementRMAInfoProxy;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCLogicProduct;
import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.product.RCRMAChildrenReplacementEvent;
import com.shrct.businessprocess.product.impl.RCProductSpecificationImpl;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCCHILDRENREPLACEMENTRMAINFO_TYPE")
public class RCChildrenReplacementRMAInfoImpl extends RCFaultReportRMAInfoImpl implements RCChildrenReplacementRMAInfo {
  public RCChildrenReplacementRMAInfoImpl() {
    super();
  }
  
  public RCChildrenReplacementRMAInfoImpl(final RCFaultReportProduct product) {
    super( product);
    
  }
  
  @JoinColumn(name = "productSpec_id")
  @ManyToOne(targetEntity = RCProductSpecificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCProductSpecification productSpec;
  
  public RCProductSpecification getProductSpec() {
    return this.productSpec;
  }
  
  public RCChildrenReplacementRMAInfo setProductSpec(final RCProductSpecification productSpec) {
    this.productSpec = productSpec;
    return this;			
    
  }
  
  public String getEventTitle() {
    return "\u5B50\u8BBE\u5907RMA";
  }
  
  public String getEventDetailInfo() {
    String _entityName = this.productSpec.getEntityName();
    String _plus = ("\u4E4B\u8BBE\u5907\u578B\u53F7:" + _entityName);
    return _plus;
  }
  
  public void commit(final Date date) {
    RCFaultReportProduct _product = this.getProduct();
    RCIdentifiablePhysicalProductEntry _product_1 = _product.getProduct();
    RCLogicProduct _logicProduct = _product_1.getLogicProduct();
    String _comment = this.getComment();
    RCRMAChildrenReplacementEvent _recordChildrenReplacenebtRMA = _logicProduct.recordChildrenReplacenebtRMA(date, _comment, this.productSpec);
    final Procedure1<RCRMAChildrenReplacementEvent> _function = new Procedure1<RCRMAChildrenReplacementEvent>() {
        public void apply(final RCRMAChildrenReplacementEvent it) {
          Date _newItemArriveDate = RCChildrenReplacementRMAInfoImpl.this.getNewItemArriveDate();
          it.setNewItemArriveDate(_newItemArriveDate);
          Date _newItemInstallDate = RCChildrenReplacementRMAInfoImpl.this.getNewItemInstallDate();
          it.setNewItemInstallDate(_newItemInstallDate);
          Date _badItemReceiveDate = RCChildrenReplacementRMAInfoImpl.this.getBadItemReceiveDate();
          it.setBadItemReceiveDate(_badItemReceiveDate);
          Date _badItemReturnDate = RCChildrenReplacementRMAInfoImpl.this.getBadItemReturnDate();
          it.setBadItemReturnDate(_badItemReturnDate);
          String _supplierName = RCChildrenReplacementRMAInfoImpl.this.getSupplierName();
          it.setSupplierName(_supplierName);
          String _rmaNumber = RCChildrenReplacementRMAInfoImpl.this.getRmaNumber();
          it.setRmaNumber(_rmaNumber);
          String _caseNumber = RCChildrenReplacementRMAInfoImpl.this.getCaseNumber();
          it.setCaseNumber(_caseNumber);
          String _comment = RCChildrenReplacementRMAInfoImpl.this.getComment();
          it.setComment(_comment);
        }
      };
    ObjectExtensions.<RCRMAChildrenReplacementEvent>operator_doubleArrow(_recordChildrenReplacenebtRMA, _function);
    this.setIsFinished(Boolean.valueOf(true));
    RCFaultReportProduct _product_2 = this.getProduct();
    RCFaultReport _faultReport = _product_2.getFaultReport();
    RCFaultReportProduct _product_3 = this.getProduct();
    _faultReport.finishDeviceRMA(_product_3, "\u5B8C\u6210\u5B50\u8BBE\u5907RMA");
  }
  
  public static RCChildrenReplacementRMAInfo create(final RCFaultReportProduct product, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.customerservice.RCChildrenReplacementRMAInfo rCChildrenReplacementRMAInfo = new com.shrct.businessprocess.customerservice.impl.RCChildrenReplacementRMAInfoImpl(
    	product
    );
    objectFactory.create(rCChildrenReplacementRMAInfo);
    return rCChildrenReplacementRMAInfo;			
    
  }
  
  public static RCChildrenReplacementRMAInfo createRCChildrenReplacementRMAInfoImpl(final RCFaultReportProduct product, final IObjectFactory objectFactory, final Procedure1<RCChildrenReplacementRMAInfo> init) {
    com.shrct.businessprocess.customerservice.RCChildrenReplacementRMAInfo rCChildrenReplacementRMAInfo = new com.shrct.businessprocess.customerservice.impl.RCChildrenReplacementRMAInfoImpl(
    	product
    );
    objectFactory.create(rCChildrenReplacementRMAInfo);
    init.apply(rCChildrenReplacementRMAInfo);
    
    return rCChildrenReplacementRMAInfo;			
    
  }
  
  public RCChildrenReplacementRMAInfoProxy toProxy() {
    com.shrct.businessprocess.customerservice.proxy.RCChildrenReplacementRMAInfoProxy proxy = new com.shrct.businessprocess.customerservice.proxy.RCChildrenReplacementRMAInfoProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
